﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace OnlineMealOrdering.Extends
{
    public class AspxRoute:RouteBase
    {
        public override RouteData GetRouteData(HttpContextBase httpContext)
        {
            var virthualPath = httpContext.Request.AppRelativeCurrentExecutionFilePath;
            virthualPath = virthualPath.Substring(2).Trim('/');
            var arr = virthualPath.Split('/');
            if (arr.Length == 2)
            {
                string controller = arr[0].ToLower();
                string action = arr[1].ToLower();
                if (action.EndsWith(".aspx"))
                {
                    action = action.Substring(0, action.Length - 5);
                    var data = new RouteData(this, new MvcRouteHandler());
                    data.Values.Add("controller", controller);
                    data.Values.Add("action", action);
                    
                    return data;
                }
            }
            return null;
        }

        public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
        {
            return null;
        }
    }
}